﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using UBCon.Ribbon.Interfaces;

namespace UBCon.Ribbon
{
    [System.Windows.TemplatePart(Name = PART_MenuItemsHostName, Type=typeof(System.Windows.Controls.Panel))]
    public class RibbonMenu : ItemsControl, IRibbonControl
    {
        #region Constructors

        static RibbonMenu() 
        {
            System.Type ownerType=typeof(RibbonMenu);
            
            RibbonMenu.DefaultStyleKeyProperty.OverrideMetadata(ownerType, new System.Windows.FrameworkPropertyMetadata(ownerType));
            
           System.Windows.Input.KeyboardNavigation.TabNavigationProperty.OverrideMetadata(ownerType, new System.Windows.FrameworkPropertyMetadata(System.Windows.Input.KeyboardNavigationMode.Local));

           System.Windows.Input.KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(ownerType, new System.Windows.FrameworkPropertyMetadata(System.Windows.Input.KeyboardNavigationMode.None));
           System.Windows.Input.KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(ownerType, new System.Windows.FrameworkPropertyMetadata(System.Windows.Input.KeyboardNavigationMode.None));

            // Disable tooltips on combo box when it is open
            
        }

        public RibbonMenu()
            : base()
        {
        }
        #endregion

        #region Properties

        public System.Collections.ObjectModel.ObservableCollection<RibbonHeaderedItemsControl> HeaderedItems
        {
            get { return (System.Collections.ObjectModel.ObservableCollection<RibbonHeaderedItemsControl>)GetValue(HeaderedItemsProperty); }
            set { SetValue(HeaderedItemsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HeaderedItems.  This enables animation, styling, binding, etc...
        public static readonly System.Windows.DependencyProperty HeaderedItemsProperty =
            System.Windows.DependencyProperty.Register("HeaderedItems", typeof(System.Collections.ObjectModel.ObservableCollection<RibbonHeaderedItemsControl>), typeof(RibbonMenu), new System.Windows.FrameworkPropertyMetadata((System.Collections.ObjectModel.ObservableCollection<RibbonHeaderedItemsControl>)null));

        public System.Windows.UIElement PlacementTarget
        {
            get { return (System.Windows.UIElement)GetValue(PlacementTargetProperty); }
            set { SetValue(PlacementTargetProperty, value); }
        }

        // Using a DependencyProperty as the backing store for PlacementTarget.  This enables animation, styling, binding, etc...
        public static readonly System.Windows.DependencyProperty PlacementTargetProperty =
            System.Windows.DependencyProperty.Register("PlacementTarget", typeof(System.Windows.UIElement),
            typeof(RibbonMenu), 
            new System.Windows.FrameworkPropertyMetadata(null));


        public System.Windows.Controls.Primitives.PlacementMode Placement
        {
            get { return (System.Windows.Controls.Primitives.PlacementMode)GetValue(PlacementProperty); }
            set { SetValue(PlacementProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Placement.  This enables animation, styling, binding, etc...
        public static readonly System.Windows.DependencyProperty PlacementProperty =
            System.Windows.DependencyProperty.Register("Placement", typeof(System.Windows.Controls.Primitives.PlacementMode),
            typeof(RibbonMenu), 
            new System.Windows.FrameworkPropertyMetadata(System.Windows.Controls.Primitives.PlacementMode.Bottom));

        public bool IsOpen
        {
            get { return (bool)GetValue(IsOpenProperty); }
            set { SetValue(IsOpenProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsOpen.  This enables animation, styling, binding, etc...
        public static readonly System.Windows.DependencyProperty IsOpenProperty =
                System.Windows.DependencyProperty.Register("IsOpen", typeof(bool),
                typeof(RibbonMenu), 
                new System.Windows.FrameworkPropertyMetadata(false, 
                System.Windows.FrameworkPropertyMetadataOptions.Journal|System.Windows.FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        [System.ComponentModel.Browsable(false)]
        public object HighlightedItem
        {
            get { return (object)GetValue(HighlightedItemProperty); }
        }

        // Using a DependencyProperty as the backing store for HighlightedItem.  This enables animation, styling, binding, etc...
        internal static readonly System.Windows.DependencyPropertyKey HighlightedItemPropertyKey =
            System.Windows.DependencyProperty.RegisterReadOnly("HighlightedItem", typeof(object), typeof(RibbonMenu), new System.Windows.PropertyMetadata(null));

        public static readonly System.Windows.DependencyProperty HighlightedItemProperty = RibbonMenu.HighlightedItemPropertyKey.DependencyProperty;
        
        #endregion

        #region Depenency Property Changed Callbacks
        #endregion

        #region Overrides

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ItemsHost = GetTemplateChild(PART_MenuItemsHostName) as System.Windows.Controls.Panel;
        }
        #endregion

        #region Private Utilities
        #endregion

        #region Event Handlers
        #endregion

        #region Fields

        internal System.Windows.Controls.Panel ItemsHost;

        private const string PART_MenuItemsHostName = "PART_MenuItemsHost";

        #endregion

        #region Events
        #endregion

        #region IRibbonControl Implementation

        /// <summary>
        /// Gets a boolean value indicating whether the contol's size is large
        /// </summary>
        public bool IsLarge
        {
            get { return true; }
        }

        #endregion
    }
}
